const db=require('./db.js');
//const cookieParser = require('cookie-parser');
let showAllBook=(req,res)=>{
    let sql='select * from book';
    db.base(sql,null,(result)=>{
        res.cookie('name','boss',{path:'/',})
        res.json(result);
    })
}
let toAddBook=(req,res)=>{
    let sql='insert into Book set?';
    let data=req.body;
    db.base(sql,data,(result)=>{
        res.json({flag:1})
    })
}
let toGetbookById=(req,res)=>{
    let sql='select * from Book where id=?';
    let data=[req.query.id];
    db.base(sql,data,(result)=>{
        res.json(result);
    })
}
let toDelBook=(req,res)=>{
    let sql='delete from Book where id=?';
    let data=[req.query.id];
    db.base(sql,data,(result)=>{
        res.json({flag:1});
    })
}
let toEditBook=(req,res)=>{
    let sql='update book set name=?,author=?,category=?,description=? where id=?';
    let info=req.body;
    let data=[info.name,info.author,info.category,info.description,info.id];
    db.base(sql,data,(result)=>{
        res.json({flag:1});
    })
}
module.exports={
    showAllBook:showAllBook,
    toAddBook:toAddBook,
    toGetbookById:toGetbookById,
    toDelBook:toDelBook,
    toEditBook:toEditBook,
}